import { createApp, nextTick,  } from 'vue';
import { createPinia } from "pinia";
import App from "./App.vue";
import router from "./router";
// import VueUeditorWrap from 'vue-ueditor-wrap'
import ElementPlus from "element-plus";
import axios from "axios";
// import { i18n } from '@/locales'
import "element-plus/dist/index.css";
import "element-plus/theme-chalk/dark/css-vars.css";
import "./registerServiceWorker";
import "@icon-park/vue-next/styles/index.css";
import "prosemirror-view/style/prosemirror.css";
import "animate.css";
import '@element-plus/icons-vue';
import "@/assets/styles/prosemirror.scss";
import "@/assets/styles/global.scss";
import "@/assets/styles/antd.scss";
import "@/assets/styles/font.scss";
import mitt from 'mitt'
import { useUserStore } from './store/layout';
import Icon from "@/plugins/icon";
import Directive from "@/plugins/directive";
import zhCn from "element-plus/es/locale/lang/zh-cn";

import {
  setDefaultDesKeyInfo,
  encodeAesString,
  decodeAesString,
} from "@/utils/cryptos";

const app = createApp(App)



app.config.globalProperties.$jiami = encodeAesString;
app.config.globalProperties.$jiemi  = decodeAesString;

app.config.performance =true
app.config.warnHandler = () => null;
// function permissionJudge(value: string, userStore: any) {
//   const list = userStore.ButtonPermission;
//   for (let item of list) {
//     if (item.permission === value) {
//       return true;
//     }
//   }
//   return false;
// }
// 自定义指令-权限按钮
app.directive('has', {
  mounted(el, binding) {
    const userStore = useUserStore();
    
    nextTick(() => {
      if (!permissionJudge(binding.value, userStore)) {
        el.parentNode?.removeChild(el);
      }
    });
  }
});
function permissionJudge(value: any, userStore:any) {
  const list = userStore.ButtonPermission;
  for (let item of list) {
    if (item === value) {
      return true;
    }
  }
  return false;
}
app.config.globalProperties.Bus = mitt()

app.use(Icon);
app.use(Directive);

app.use(createPinia());
// app.use(i18n)
app.use(router);
app.use(ElementPlus, {
  locale: zhCn,
});

// 创建事件总线
// app.use(VueUeditorWrap)
app.mount("#app");
